import { getToken, setToken, removeToken } from '@/utils/auth'

const state = {
  token: getToken(),
  userInfo: {}
}
const mutations = {
  // 给state.token赋值
  setStateToken(state, token) {
    state.token = token
    // 给本地的token赋值
    setToken(token)
  },
  removeToken(state) {
    state.token = null
    removeToken()
  }
}
const actions = {
  // 给外面一个调用登录接口,将token传到setStateToken里
  async login(context, data) {
    console.log(data)
    context.commit('setStateToken', '123456')
  }
  // loginOut(context, token) {
  //   context.commit('removeToken', token)
  // }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
